import {Injectable} from '@angular/core';
import {BaseHttpService} from '../base-http.service';
import {Observable} from 'rxjs';
import {PageInfo, SearchCommonVO} from '../../types';


export interface ExamsManageListModel {
  id: number;
  name: string;
  remark?: string;
  countScore: number;
  passScore: number;
  startTime?: Date;
  endTime?: Date;
  testState?: number;
  duration?: number;
  testTime: string;
}

export interface ExamsManageModel {
  countScore: number;
  difficultyGrade: number;
  duration: number;
  endTime: Date;
  judgeScore: number;
  multiScore: number;
  name: string;
  omitScore: number;
  passScore: number;
  questionTestBankVos: QuestionTestBank[];
  radioScore: number;
  remark: string;
  startTime: Date;
  timeLimitFlag: boolean;
  creatTime: [Date, Date];
}

export interface QuestionTestBank {
  id?: number;
  judgeNum: number;
  multiNum: number;
  questionBankId: number;
  radioNum: number;
}

/*题库下拉列表*/
export interface ExamsManageSelectList {
  id: number;
  name: string;
  remark?: string;
  radio?: Date;
  judge?: string;
  createTime?: Date;
}

/*考试用户详情*/
export interface TestUserList extends QueryTestUserParam {
  questionTestName?: string;
  userName: string;
  countTest: number;
  maxScore: number;
  passFlag: boolean;
  lastTestTime: Date;
}

/*用户考试明细*/
export interface TestUserDetail extends QueryTestUserParam {
  id?: number;
  useTime: Date;
  startTime: Date;
  score: number;
  passFlag: boolean;
}

export interface QueryTestUserParam {
  userId: number;
  questionTestId: number;
}

@Injectable({
  providedIn: 'root'
})


export class ExamsManageService {

  constructor(public http: BaseHttpService) {
  }

  /*获取题库列表数据*/
  public getExamsManageSelectList(param: SearchCommonVO<any>): Observable<PageInfo<ExamsManageSelectList>> {
    return this.http.post('/question-bank', param);
  }

  /*获取考试列表数据*/
  public getExamsManageList(param: SearchCommonVO<any>): Observable<PageInfo<ExamsManageListModel>> {
    return this.http.post('/question-test', param);
  }

  /*新增考试名称*/
  public addExamsManage(param: ExamsManageModel): Observable<ExamsManageModel> {
    return this.http.post('/insert-question-test', param, {needSuccessInfo: true});
  }

  /*编辑考试信息*/
  public editExamsManage(param: ExamsManageModel): Observable<any> {
    return this.http.put('/question-test', param, {needSuccessInfo: true});
  }


  /*考试详情*/
  public getExamsManageDetail(id: number): Observable<ExamsManageModel> {
    return this.http.get(`/question-test/${id}`);
  }

  /*用户考试明细接口*/
  public getUserExamsDetail(param: QueryTestUserParam): Observable<TestUserDetail[]> {
    return this.http.get('/user-detail-question-test', param);
  }

  /*考试用户详情*/
  public userExamsDetailList(param: SearchCommonVO<any>): Observable<PageInfo<TestUserList>> {
    return this.http.post('/user-question-test', param);
  }

  /*删除考试*/
  public delExamsManage(idArray: number[]): Observable<void> {
    return this.http.post('/del-question-test', {ids: idArray}, {needSuccessInfo: true});
  }
}
